package com.teprinciple.wanandroid

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.Composable
import androidx.activity.compose.setContent
import androidx.compose.animation.Crossfade
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.updateTransition
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.lazy.GridCells
import androidx.compose.foundation.lazy.LazyVerticalGrid
import androidx.compose.material.SwipeToDismiss
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintLayout
import com.teprinciple.wanandroid.ui.theme.WanAndroidTheme
import com.teprinciple.wanandroid.ui.commom.BottomBar
import com.teprinciple.wanandroid.ui.commom.BottomTab
import com.teprinciple.wanandroid.ui.page.HomePage
import com.teprinciple.wanandroid.ui.page.MinePage
import com.teprinciple.wanandroid.ui.page.QAPage
import com.teprinciple.wanandroid.ui.page.SystemPage

import androidx.compose.runtime.getValue
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import com.google.accompanist.pager.ExperimentalPagerApi

class MainActivity : AppCompatActivity() {

    private val tabs by lazy {
        arrayListOf(
            BottomTab("首页", R.mipmap.ic_tab_home),
            BottomTab("问答", R.mipmap.ic_tab_qa),
            BottomTab("体系", R.mipmap.ic_tab_system),
            BottomTab("我的", R.mipmap.ic_tab_mine),
        )
    }

    @ExperimentalPagerApi
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            WanAndroidApp()
        }
    }

    @ExperimentalPagerApi
    @Composable
    private fun WanAndroidApp() {

        WanAndroidTheme {
            var current by rememberSaveable {
                mutableStateOf(0)
            }

            Column() {
                // 淡入淡出效果
                Crossfade(targetState = current, Modifier.weight(1f)) { screen ->
                    when (screen) {
                        0 -> HomePage()
                        1 -> QAPage()
                        2 -> SystemPage()
                        3 -> MinePage()
                    }
                }

                BottomBar(tabs = tabs, current = current, onTabClick = {
                    current = it
                })
            }
        }
    }
}